package org.emp.controller;

import org.emp.common.Result;
import org.emp.exception.LoginException;
import org.emp.pojo.dto.AdminLoginDTO;
import org.emp.pojo.dto.EmpLoginDTO;

import org.emp.pojo.entity.Emp;
import org.emp.service.LoginService;
import org.emp.utils.PasswordEncryptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 加油
 *
 * @author konglingfeng
 * @date 2025/8/9
 * @desc
 */
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 员工登录
     * @param empLoginDto
     * @return
     */
    @GetMapping("/emp/login")
    public Result<String> empLogin(@RequestBody EmpLoginDTO empLoginDto) {
        try{
            Result<String> result = loginService.findEmpByEmUsername(empLoginDto);
            return result;
        }catch (LoginException e){
            throw e;//抛出登录异常  登录异常是自定义的
        }
    }

    /**
     * 管理员登录
     * @param adminLoginDTO
     * @return
     */
    @GetMapping("/admin/login")
    public Result<String> adminLogin(@RequestBody AdminLoginDTO adminLoginDTO) {
        try{
            Result<String> result = loginService.findAdminByEmUsername(adminLoginDTO);
            return result;
        }catch (LoginException e){
            throw e;//抛出登录异常  登录异常是自定义的
        }
    }



}
